<?php 
namespace Api\Controller;
use Think\Controller;

class IndexController extends BaseController{

	public function index(){
		$user=I('post.user');
		$login=M('login');

		$dkinfo=M('dkinfo');//贷款表实例化
		$dksx=M('dksx');//贷款授信表实例化
		$hkjhman =M('hkjhman');//今日应还款表实例化
		$DkLxInfo=M('dklxinfo');//今日收息表实例化
		$hdinfo=M('hdinfo');//今日收本表实例化
		$now=date('Y-m-d 00:00:00.000',time());//今天的日期

		$show=$login->where(['CzyName'=>$user])->find();
		$nowmonth=date('m');
		
		//判断用户权限显示
		if ($show['qxshowall']==1) {

			
			$DkshNum=$dkinfo->where(['shenHe'=>0])->count();//贷款审核数量

			$DkinfoNum=$dkinfo->where(['jbdate'=>$now])->count();//今天新增贷款数量
			$DksxNum=$dksx->where(['jbdate'=>$now])->count();//今天新增授信数量
			$Jrhk=$hkjhman->where(['h_Date'=>$now,'h_hkQk'=>'未还款'])->count();//今天需要还款的数量
			
			$YwspNum=$dksx->where(['YwSplx'=>'未审'])->count();//业务审批数量

			
			$FkNum=$dksx->where(['FkSplx'=>'未审','YwSplx'=>'通过'])->count();//风控审批数量
			$FkfNum=$dksx->where(['FkFSplx'=>'未审','FkSplx'=>'通过'])->count();//风控负责人审批数量
			$JlNum=$dksx->where(['JlSplx'=>'未审','FkFSplx'=>'通过'])->count();//经理审批数量
			$SpNum=$YwspNum+$FkNum+$FkfNum+$JlNum;//授信待审总审批数量
			

			$DkEndNum=$dkinfo->where(['EndDate'=>$now])->count();//今天到期的贷款数量
			$DkgtNum=$dkinfo->where(['EndDate'=>['lt',$now]])->count();//今天已经过期的贷款数量

			//本月及前面十一个月贷款金额
			
			$arr=array();
			for ($i=1; $i <$nowmonth+1 ; $i++) { 
				$upmonthfirstday=monthfirstday($i);
				$upmonthlastday=monthlastday($i);
				
				$arr[]=$dkinfo->where(array('BeginDate'=>array('between',array($upmonthfirstday,$upmonthlastday))))->sum('YsMoney');
				// $Dkmoney[] = substr($arr[$i],0,2);
			}
			$marr=array();
			for ($i=1; $i <$nowmonth+1 ; $i++) { 
				$marr[]=month($i);
			}
			$Dkmonth=$marr;
			 //$Dkmoney=;//本月及前面十一个月贷款金额
			for($i=0;$i<$nowmonth;$i++){
				if($arr[$i]!=null){
					$Dkmoney[]=substr($arr[$i],0,strlen($arr[$i])-2);

				}else{
					$Dkmoney[]=$arr[$i];
				}
			}
			

			//本月及前面十一个月收款金额
			$LxArr=array();
			$BjArr=array();
			$Skmoney=array();
			for ($i=1; $i <$nowmonth+1 ; $i++) { 
				$upmonthfirstday=monthfirstday($i);//每月第一天
				$upmonthlastday=monthlastday($i);//每月最后一天

				$LxArr[]=$DkLxInfo->where(array('x_Jbdate'=>array('between',array($upmonthfirstday,$upmonthlastday))))->sum('x_LxMoney');//本月收息金额

				$BjArr[]=$hdinfo->where(array('h_jbDate'=>array('between',array($upmonthfirstday,$upmonthlastday))))->sum('h_Money');//本月收本金额
				
				
			}
			for ($i=0; $i <$nowmonth ; $i++) { 
				$Skmoney[]=$LxArr[$i]+$BjArr[$i];
			}
			 
			
			$data=array();
			$array=array();
			foreach ($Dkmoney as $k => $v) {
				$array['value']=$v;
				
			}
			foreach ($Dkmonth as $key => $v) {
				$array['name']=$v.'月';
				switch ($v) {
					case '1':
						$array['itemStyle']=['normal'=>['color'=>'#32C5E9']];
						break;
					case '2':
						$array['itemStyle']=['normal'=>['color'=>'#67E0E3']];
						break;
					case '3':
						$array['itemStyle']=['normal'=>['color'=>'#FFDB5C']];
						break;
					case '4':
						$array['itemStyle']=['normal'=>['color'=>'#ff9f7f']];
						break;
					case '5':
						$array['itemStyle']=['normal'=>['color'=>'#37A2DA']];
						break;
					case '6':
						$array['itemStyle']=['normal'=>['color'=>'#fb7293']];
						break;
					case '7':
						$array['itemStyle']=['normal'=>['color'=>'#9FE6B8']];
						break;
					case '8':
						$array['itemStyle']=['normal'=>['color'=>'#E062AE']];
						break;
					case '9':
						$array['itemStyle']=['normal'=>['color'=>'#E690D1']];
						break;	
					case '10':
						$array['itemStyle']=['normal'=>['color'=>'#e7bcf3']];
						break;
					case '11':
						$array['itemStyle']=['normal'=>['color'=>'#9d96f5']];
						break;
					case '12':
						$array['itemStyle']=['normal'=>['color'=>'#8378EA']];
						break;
					default:
						# code...
						break;
				}
				


				$data[]=$array;
			}

			



			$this->ajaxReturn(['code'=>101,'msg'=>'查询成功','data'=>['DkshNum'=>$DkshNum,'DkinfoNum'=>$DkinfoNum,'DksxNum'=>$DksxNum,'Jrhk'=>$Jrhk,'SpNum'=>$SpNum,'DkEndNum'=>$DkEndNum,'DkgtNum'=>$DkgtNum,'Dkmoney'=>$Dkmoney,'Dkmonth'=>$Dkmonth,'Skmoney'=>$Skmoney,'row'=>$data]]);



		}else{

			$DkshNum=$dkinfo->where(['shenHe'=>0,'LrCzy'=>$user])->count();//贷款审核数量
			$DkinfoNum=$dkinfo->where(['jbdate'=>$now,'LrCzy'=>$user])->count();//今天新增贷款数量
			$DksxNum=$dksx->where(['jbdate'=>$now,'Lrczy'=>$user])->count();//今天新增授信数量
			//print_r($DksxNum);die;
			//今天需要还款的数量
			$Jrhk=$hkjhman->where(['h_Date'=>$now,'h_hkQk'=>'未还款','Lrczy'=>$user])->count();


			//$where['YwSplx']=[['gt','未审'],['gt',null],'or'];
			
			$YwspNum=$dksx->where(['YwSplx'=>'未审','Lrczy'=>$user])->count();//业务审批数量
			$FkNum=$dksx->where(['FkSplx'=>'未审','YwSplx'=>'通过','Lrczy'=>$user])->count();//风控审批数量
			$FkfNum=$dksx->where(['FkFSplx'=>'未审','FkSplx'=>'通过','Lrczy'=>$user])->count();//风控负责人审批数量

			$JlNum=$dksx->where(['JlSplx'=>'未审','FkFSplx'=>'通过','Lrczy'=>$user])->count();//经理审批数量
			$SpNum=$YwspNum+$FkNum+$FkfNum+$JlNum;//总审批数量
			
			$DkEndNum=$dkinfo->where(['EndDate'=>$now,'Lrczy'=>$user])->count();//今天到期的贷款数量
			$DkgtNum=$dkinfo->where(['EndDate'=>['lt',$now],'Lrczy'=>$user])->count();//今天已过期的贷款数量
			

			//本月及前面十一个月贷款金额
			$arr=array();
			$Dkmoney=array();
			for ($i=1; $i <$nowmonth+1 ; $i++) { 
				$upmonthfirstday=monthfirstday($i);
				$upmonthlastday=monthlastday($i);
				$where['BeginDate']  = array('between',array($upmonthfirstday,$upmonthlastday));//
				$where['LrCzy']=$user;
				$arr[]=$dkinfo->where($where)->sum('YsMoney');
				
			}
			$marr=array();
			for ($i=1; $i <$nowmonth+1 ; $i++) { 
				$marr[]=month($i);
			}
			$Dkmonth=$marr;
			$Dkmoney=$arr;//本月及前面十一个月贷款金额

			//本月及前面十一个月收款金额
			$LxArr=array();
			$BjArr=array();
			$Skmoney=array();
			for ($i=1; $i <$nowmonth+1 ; $i++) { 
				$upmonthfirstday=monthfirstday($i);//每月第一天
				$upmonthlastday=monthlastday($i);//每月最后一天

				$LxArr[]=$DkLxInfo->where(array('x_Jbdate'=>array('between',array($upmonthfirstday,$upmonthlastday)),'lrCzy'=>$user))->sum('x_LxMoney');//本月收息金额

				$BjArr[]=$hdinfo->where(array('h_jbDate'=>array('between',array($upmonthfirstday,$upmonthlastday)),'lrczy'=>$user))->sum('h_Money');//本月收本金额
				
				
			}
			for ($i=0; $i <$nowmonth ; $i++) { 
					$Skmoney[]=$LxArr[$i]+$BjArr[$i];//本月及前面十一个月收款金额
				}

				$data=array();
			$array=array();
			foreach ($Dkmoney as $k => $v) {
				$array['value']=$v;
				
			}
			foreach ($Dkmonth as $key => $v) {
				$array['name']=$v.'月';
				switch ($v) {
					case '1':
						$array['itemStyle']=['normal'=>['color'=>'#32C5E9']];
						break;
					case '2':
						$array['itemStyle']=['normal'=>['color'=>'#67E0E3']];
						break;
					case '3':
						$array['itemStyle']=['normal'=>['color'=>'#FFDB5C']];
						break;
					case '4':
						$array['itemStyle']=['normal'=>['color'=>'#ff9f7f']];
						break;
					case '5':
						$array['itemStyle']=['normal'=>['color'=>'#37A2DA']];
						break;
					case '6':
						$array['itemStyle']=['normal'=>['color'=>'#fb7293']];
						break;
					case '7':
						$array['itemStyle']=['normal'=>['color'=>'#9FE6B8']];
						break;
					case '8':
						$array['itemStyle']=['normal'=>['color'=>'#E062AE']];
						break;
					case '9':
						$array['itemStyle']=['normal'=>['color'=>'#E690D1']];
						break;	
					case '10':
						$array['itemStyle']=['normal'=>['color'=>'#e7bcf3']];
						break;
					case '11':
						$array['itemStyle']=['normal'=>['color'=>'#9d96f5']];
						break;
					case '12':
						$array['itemStyle']=['normal'=>['color'=>'#8378EA']];
						break;
					default:
						# code...
						break;
				}
				


				$data[]=$array;
			}



			$this->ajaxReturn(['code'=>101,'msg'=>'查询成功','data'=>['DkshNum'=>$DkshNum,'DkinfoNum'=>$DkinfoNum,'DksxNum'=>$DksxNum,'Jrhk'=>$Jrhk,'SpNum'=>$SpNum,'DkEndNum'=>$DkEndNum,'DkgtNum'=>$DkgtNum,'Dkmoney'=>$Dkmoney,'Skmoney'=>$Skmoney,'Dkmonth'=>$Dkmonth,'row'=>$data]]);



		}
		
		
	}











}








			// $firstday =date('Y-m-01 00:00:00.000',time());//本月第一天

			// $lastday =date('Y-m-t 23:59:59.999',time());//本月最后一天

			// $where['jbdate']  = array('between',array($firstday,$lastday));//判断条件，贷款日期是否在本月之中

			// $Dkmoney=$dkinfo->where($where)->sum('YsMoney');//本月贷款金额






 ?>